<?php
	include('../configs/connect.php');
	include('db.php');
	$db = new db_mysql();
	$db->connect($host,$name,$pass,$database);
 /*	if(isset($_GET['cat'])){
		$cat = $_GET['cat'];
		$donvi = $_GET['donvi'];
		$hocvu = $_GET['hocvu'];
        $nganh=$_GET['nganh'];
        
		if($cat=="mon"){
			$sql = "SELECT mh.madm_mh, mh.ten_mh FROM tbl_lopmon AS lm
                    INNER JOIN tbl_lopmon_monctdt AS lmctdt ON lm.ma_lopmon = lmctdt.ma_lopmon
                    INNER JOIN tbl_mon_ctdt AS mctdt ON lmctdt.ma_mon_ctdt = mctdt.ma_mon_ctdt
                    INNER JOIN tbl_ctdt AS ctdt ON mctdt.ma_ctdt = ctdt.ma_ctdt
                    INNER JOIN dm_monhoc AS mh ON mctdt.ma_monhoc = mh.madm_mh
                    WHERE lm.ma_donvi = '$donvi' AND lm.ma_donvihocvu='$hocvu' 
                    AND ctdt.madm_nganh = '$nganh'";
			$marr = $db->getList($sql);
				echo "<option value=\"00\">Chọn môn thi</option>";
			foreach($marr as $mon){
				echo "<option value=".$mon['madm_mh'].">".$mon['ten_mh']."</option>";
			}
           
		}
	}
     */
    
   
    if(isset($_GET['cat'])){
		$cat = $_GET['cat'];
		$donvi = $_GET['donvi'];
		if(isset($_GET['nganh'])){
			$nganh = $_GET['nganh'];
		}
		if(isset($_GET['hocvu'])){
			$hocvu = $_GET['hocvu'];
			}
		if($cat=="mon"){
			$sql = "SELECT DISTINCT mh.ten_mh, mh.madm_mh from dm_monhoc AS mh
					INNER JOIN tbl_mon_ctdt AS mctdt ON mctdt.ma_monhoc = mh.madm_mh
					INNER JOIN tbl_lopmon_monctdt AS lmctdt ON lmctdt.ma_mon_ctdt = mctdt.ma_mon_ctdt
					INNER JOIN tbl_lopmon AS lm ON lm.ma_lopmon = lmctdt.ma_lopmon
					INNER JOIN tbl_ctdt AS ctdt ON mctdt.ma_ctdt = ctdt.ma_ctdt
					WHERE lm.ma_donvi = '$donvi' AND lm.ma_donvihocvu = '$hocvu' AND ctdt.madm_nganh = $nganh";
			$marr = $db->getList($sql);
				echo "<option value=\"00\">Chọn môn học</option>";
			foreach($marr as $mon){
				echo "<option value=\"".$mon['madm_mh']."\">".$mon['ten_mh']."</option>";
			}
		}
		else if($cat="nganh"){
		$sql="SELECT ctdt.madm_nganh, dmn.ten_nganh FROM tbl_ctdt AS ctdt
				INNER JOIN tbl_donvi_ctdt AS dvctdt ON dvctdt.ma_ctdt = ctdt.ma_ctdt
				INNER JOIN dm_nganh AS dmn ON dmn.madm_nganh = ctdt.madm_nganh
				WHERE dvctdt.ma_donvi = '$donvi'";
		
		$narr = $db->getList($sql);

			echo "<option value=\"00\">Chọn ngành</option>";

			foreach($narr as $nganh){
			echo "<option value=\"".$nganh['madm_nganh']."\">".$nganh['ten_nganh']."</option>";
			}
		}
	}
	else if($_GET['action']=="dsbylopmon"){
			$madonvi = $_GET['donvi'];
			$mahocvu = $_GET['hocvu'];
            $manganh=$_GET['nganh'];
			//$mahoidong = $db->getOneField("SELECT ma_hoidong FROM tbl_hoidongthi WHERE ma_donvihocvu = '$mahocvu' AND ma_trungtam = '$madonvi'");
	       	$sql ="SELECT lm.ma_lopmon, lm.ten_lopmon, mh.ten_mh,lm.ngaybatdau,lm.ngayketthuc  FROM tbl_lopmon AS lm
                                    INNER JOIN tbl_lopmon_monctdt AS lmctdt ON lm.ma_lopmon = lmctdt.ma_lopmon
                                    INNER JOIN tbl_mon_ctdt AS mctdt ON lmctdt.ma_mon_ctdt = mctdt.ma_mon_ctdt
                                    INNER JOIN tbl_ctdt AS ctdt ON mctdt.ma_ctdt = ctdt.ma_ctdt
                                    INNER JOIN dm_monhoc AS mh ON mctdt.ma_monhoc = mh.madm_mh
                                    WHERE lm.ma_donvi = '$madonvi' AND lm.ma_donvihocvu='$mahocvu' AND ctdt.madm_nganh = '$manganh'";
		
                   //     if(isset($_GET['mon'])){
                	//			$mon = $_GET['mon'];
                	//			$sql.=" AND mh.madm_mh = '$mon'"; }
             $listdslopmon = $db->getList($sql);           
        	echo "	<table><tbody>
			<tr class='alt-row'>
				<th>Mã lớp môn</th>
				<th>Tên lớp môn</th>
                <th>Tên môn học</th>
                <th>Ngày bắt đầu</th>
                <th>ngày kết thúc</th>
				<th>trạng thái</th>
				<th>Tác vụ</th>
			</tr>
			";
        
			foreach($listdslopmon as $dslm){
				echo "<tr>
				<td>".$dslm['ma_lopmon']."</td>
				<td>".$dslm['ten_lopmon']."</td>
                <td>".$dslm['ten_mh']."</td>
                <td>".$dslm['ngaybatdau']."</td>
                <td>".$dslm['ngayketthuc']."</td>
				<td>thạng thái</td>
				<td>";
                echo "<a href='index.php?muc=nhom1&modul=ds_diemdk&malopmon=".$dslm['ma_lopmon']."'>Chi tiết</a>";
                //<input class='button' type='button' name='chitiet' value='chi tiết'>
                echo "</td></tr>";
			}
			echo "</tbody></table>";
		}


    
    ?>